package xzy.com.config.jwt;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import xzy.com.config.jwt.interceptor.AuthenticationInterceptor;

//import com.jwt.token.interceptor.AuthenticationInterceptor;

//
/**注册拦截器：WebConfig.java
 * 在配置类上添加了注解@Configuration，
 * 标明了该类是一个配置类并且会将该类作为一个SpringBean添加到IOC容器内
 * @author jinbin
 * @date 2018-07-08 22:33 * 
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
	//添加jwt拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor())
                .addPathPatterns("/**");    // 拦截所有请求，通过判断是否有 @LoginRequired 注解 决定是否需要登录
    }
    // jwt拦截器
    @Bean
    public AuthenticationInterceptor authenticationInterceptor() {
        return new AuthenticationInterceptor();
    }   
}
